<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonModule for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Menu\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class MenuController extends AbstractActionController
{
    protected $menuTable; 
    
	public function getMenuTable()
    {
    	if(!$this->menuTable)
    	{
    		$this->menuTable = $this->getServiceLocator()->get('menuTable');
    	}
    	
    	return $this->menuTable;
    }
	
	public function indexAction()
    {
        $matches = $this->getEvent()->getRouteMatch();
    	$page = $matches->getParam('page', 1);
    	
    	$resultSet = $this->getMenuTable()->fetchAll();
    	$resultSet->buffer();
    	$resultSet->next();
    	
    	$paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\Iterator($resultSet));
    	
    	$paginator->setCurrentPageNumber($page);
    	$paginator->setItemCountPerPage(20);
    	
    	return array('menuArray' => $paginator);
    }
}
